
package com.jf.cloud.combo.listener;

import com.jf.cloud.api.product.feign.ShopCartFeignClient;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 套餐
 * @author zz
 * @date 2022/9/8 15:48
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.COMBO_DELETE_OR_DISABLED,consumerGroup = RocketMqConstant.COMBO_DELETE_OR_DISABLED)
public class ComboListener implements RocketMQListener<List<Long>> {

    @Autowired
    private ShopCartFeignClient shopCartFeignClient;

    /**
     * 失效或者删除套餐时移除购物车商品
     * @param comboIdList
     */
    @Override
    public void onMessage(List<Long> comboIdList) {
        if (comboIdList.size() != 0 && Objects.nonNull(comboIdList)){
            shopCartFeignClient.deleteCartByComboUpdate(comboIdList,-1L,-1L);
        }
    }
}
